package com.fenxiangtech.mall.enums;

/**
 * @author zhangjiashun
 */
public enum ExceptionEnum {
    NOT_FOUND(404, "资源未找到, 请检查请求参数", 404),
    UNKNOWN_ERROR(999, "未知错误", 400),
    BANNER_MISSING(40000, "Banner不存在, 请检查请求参数", 400),
    PARAMETER_MISMATCH(1015, "请求参数不匹配", 400),
    THEME_MISSING(30000, "Theme不存在, 请检查请求参数", 400),
    PRODUCT_MISSING(20000, "Product不存在, 请检查请求参数", 400),
    STOCK_SHORTAGE(20001, "库存不足", 500),
    CATEGORY_MISSING(50000, "Category不存在, 请检查请求参数", 400),
    USER_MISSING(60000, "用户不存在", 400),
    USER_INVALID(60001, "用户名或密码错误", 401),
    WECHAT_INNER_ERROR(70000, "获取session_key及openID时异常，微信内部错误", 500),
    NO_WECHAT_CODE(70001, "没有code还想拿token？做梦哦", 400),
    REDIS_CACHE_ERROR(10009, "Redis缓存出错", 500),
    TOKEN_INVALID(10001, "Token已过期或无效", 401),
    FORBIDDEN_ACCESS(10001, "权限不够", 403),
    ORDER_MISSING(10003, "订单不存在", 400),
    ORDER_PAID(80003, "订单已经支付过啦", 400),
    ORDER_UNPAID(80004, "订单未支付", 400),
    ORDER_DELIVERED(80005, "已经发货了, 不能再发了", 400)
    ;

    private final int code;

    private final String msg;

    private final int statusCode;

    ExceptionEnum(int code, String msg, int statusCode) {
        this.code = code;
        this.msg = msg;
        this.statusCode = statusCode;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public static ExceptionEnum codeOf(int code) {
        for (ExceptionEnum exceptionEnum : values()) {
            if (exceptionEnum.getCode() == code) {
                return exceptionEnum;
            }
        }
        return null;
    }
}
